home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BTREE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.9 KB  |  52 lines

  1. /*  btree.h - data structures and constants for BTREE modue */
  2. #define EOIX     (-2)        /* return value for end-of-index */
  3. #define IX_FAIL  (-1)        /* return value for failed operation */
  4. #define IX_OK      0        /* return value for success */
  5.  
  6. typedef  long  RECPOS ;     /* file pos. of index block/data rec. */
  7. #define NULLREC  (-1L)        /* special value for RECPOS */
  8.  
  9. #define MAXKEY     100        /* maximum length of a key */
  10.  
  11. typedef struct            /* entry format in index */
  12.   {  RECPOS rptr ;        /* points to lower level */
  13.      char  key[MAXKEY]    ;    /* start of key value */
  14.                 /* actual data type unknown */
  15.   }  ENTRY ;
  16.  
  17. #define IXB_SIZE     1024    /* no. bytes in a block ( on disk ) */
  18.     /* IXB_SIZE = IXB_SIZE - sizeof(int)*2 - sizeof(long) */
  19. #define IXB_SPACE    1016    /* no. bytes of entry space in block */
  20.  
  21. typedef struct            /* index block format */
  22.   {  RECPOS   brec  ;        /* index file location of block */
  23.                 /* or location of next free block */
  24.      int   bend  ;        /* first unused location in block */
  25.      int   lvl     ;        /* records level no. (-1 = free) */
  26.      char  entries[IXB_SPACE] ; /* space for entries */
  27.   }  BLOCK ;
  28.  
  29. #define MAX_LEVELS   4        /* four index levels permitted */
  30.  
  31. typedef struct            /* disk file index descriptor */
  32.   {  int   nl ;         /* number of index levels */
  33.      RECPOS   rb ;        /* location of root block in file */
  34.      RECPOS   ff ;        /* location of first free block */
  35.      ENTRY    dume ;        /* dummy entry */
  36.   }  IX_DISK  ;
  37.  
  38. typedef struct            /* in-memory index descriptor */
  39.   {  int   ixfile ;        /* descriptor of open index file */
  40.      struct
  41.     {  RECPOS   cblock ;    /* current block number */
  42.        int     coffset ;    /* current offset within block */
  43.     }  pos[MAX_LEVELS] ;
  44.      int   (*pcomp) () ;    /* address of compare function */
  45.      int   (*psize) () ;    /* address of entry size */
  46.      BLOCK cache[MAX_LEVELS] ;    /* cache for current blocks */
  47.      IX_DISK  dx ;        /* disk resident stuff */
  48.   }  IX_DESC ;
  49.  
  50.  
  51.  
  52.